package br.edu.ufcg.msnlab2.grupo09;

import java.math.BigDecimal;
import java.util.ArrayList;

import br.edu.ufcg.msnlab2.InvalidFunctionException;
import br.edu.ufcg.msnlab2.grupo09.ode.rungeKutta.RungeKutta;
import br.edu.ufcg.msnlab2.grupo09.ode.rungeKutta.RungeKuttaFehlberg;
import br.edu.ufcg.msnlab2.misc.Function;
import br.edu.ufcg.msnlab2.misc.FunctionImpl;



public class RungeKuttaIterationTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		final int IGUAL = 1;
		final int DIFERENTE = 0;
		ArrayList vezes = new ArrayList();
		for(int  i = 0; i < 10000; i++){
			Function equation = null;
			try {
				equation = new FunctionImpl("30-6*y");
			} catch (InvalidFunctionException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			RungeKutta solve = new RungeKutta(equation);
			try {
				double result = solve.rungekutta(0, 5, 1, 50);
				BigDecimal testBigY = new BigDecimal(4.99999999999960476060323344427160918712615966796875);
				if(testBigY.equals(new BigDecimal(result))){
					vezes.add(IGUAL);
				} else {
					vezes.add(DIFERENTE);
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		int contVezIgual = 0;
		int contVezDif = 0;
		for(int i = 0; i < 10000; i++){
			Integer num = (Integer)vezes.get(i);
			if(IGUAL == num){
				contVezIgual++;
			} else {
				contVezDif++;
			}
		}
		System.out.println("Para Runge-Kuuta");
		System.out.println("De mil 10000 vez rodando, deu: " + contVezIgual + " vezes iguais e " + contVezDif + " vezes diferente");
		for(int  i = 0; i < 10000; i++){
			Function equation = null;
			try {
				equation = new FunctionImpl("30-6*y");
			} catch (InvalidFunctionException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			RungeKuttaFehlberg solve = new RungeKuttaFehlberg(equation);
			try {
				double result = solve.rungekuttafehlberg(0, 5, 1, 50);
				BigDecimal testBigY = new BigDecimal(4.999999999999626965063725947402417659759521484375);
				if(testBigY.equals(new BigDecimal(result))){
					vezes.add(IGUAL);
				} else {
					vezes.add(DIFERENTE);
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		contVezIgual = 0;
		contVezDif = 0;
		for(int i = 0; i < 10000; i++){
			Integer num = (Integer)vezes.get(i);
			if(IGUAL == num){
				contVezIgual++;
			} else {
				contVezDif++;
			}
		}
		System.out.println("Para Runge-Kuuta-Fehlberg");
		System.out.println("De mil 10000 vez rodando, deu: " + contVezIgual + " vezes iguais e " + contVezDif + " vezes diferente");

	}

}
